﻿@using MvcForum.Core.Constants
@using MvcForum.Web.Application.ExtensionMethods
@model MvcForum.Web.ViewModels.Admin.BannedEmailListViewModel
@{
    ViewBag.Title = "Banned Email";
}

<div class="panel">
    <div class="panel-heading">
        <h5>@ViewBag.Title</h5>
    </div>
    <div class="panel-content">
        <p>This allows you to ban emails and domains used by members trying to register. Either add in a full email, or you can ban an entire domain by using a wildcard match.</p>
        <p> i.e. To ban all emails from yahoo.com just add <strong>*@@yahoo.com</strong></p>
        <div class="row">
            <div class="col-md-6">
                @using (Html.BeginForm("Index", "BannedEmail", FormMethod.Get))
                {
                    <div class="input-group tablesearch">
                        @Html.TextBoxFor(x => Model.Search, new { @class = "form-control", placeholder = "Search" })
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="submit">Search</button>
                        </span>
                    </div>
                    @Html.Hidden("p", Model.PageIndex)
                }
            </div>
            <div class="col-md-6">
                @using (Html.BeginForm("Add", "BannedEmail", FormMethod.Post))
                {
                    <div class="input-group tablesearch">
                        @Html.TextBox("Email", null, new { @class = "form-control", type = "email", placeholder = "Add new Email" })
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="submit">Add</button>
                        </span>
                    </div>
                }
            </div>
        </div>

        @if (Model.Emails.Any())
        {
            <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th style="width: 65px;">Edit</th>
                        <th>Email</th>
                        <th style="width: 65px;">Delete</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var email in Model.Emails)
                    {
                        <tr>
                            <td>
                                <span class="editbannedemail">
                                    <a href="#" class="btn-mvc">
                                        <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                    </a>
                                </span>
                                <span class="savebannedemail" style="display: none;">
                                    <a href="#" class="btn-mvc">
                                        <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                                    </a>
                                </span>
                            </td>
                            <td class="bannedemailvalue">
                                <span class="bannedemailvaluedisplay">
                                    @Html.Raw(email.Email)
                                </span>
                                <span class="bannedemailvalueedit" style="display: none;">
                                    <input data-emailid="@email.Id" data-oldvalue="@email.Email" type="text" id="@email.Id" value="@email.Email" class="bannedemailinput form-control" />
                                </span>
                            </td>
                            <td>
                                <a href="@Url.Action("Delete", new { email.Id, p = Model.PageIndex, search = Model.Search })" class="btn-mvc">
                                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                                </a>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>

            if (Model.Emails.TotalPages > 1)
            {
                @Html.Pager(Convert.ToInt32(Model.PageIndex), ForumConfiguration.Instance.AdminListPageSize, Convert.ToInt32(Model.TotalCount), new { search = Model.Search })
            }

        }
    </div>
</div>



